package com.chujian.framework.sync.aop;

import com.chujian.framework.sync.SyncConst;
import com.chujian.framework.annotation.sync.EnableSync;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.MethodMatcher;

import java.lang.reflect.Method;

@Slf4j
public class SyncMethodMatcher implements MethodMatcher {

    @Override
    public boolean matches(Method method, Class<?> targetClass) {
        String name = method.getName();
        EnableSync enableSync = targetClass.getAnnotation(EnableSync.class);
        boolean match = null != enableSync && SyncConst.NEED_SYNC_METHODS.contains(name);
        if (match) {
            log.info("class:{} method:{} syncMatched", targetClass.getName(), method.getName());
        }
        return match;
    }

    @Override
    public boolean isRuntime() {
        return false;
    }

    @Override
    public boolean matches(Method method, Class<?> targetClass, Object... args) {
        throw new UnsupportedOperationException();
    }
}
